/**
 * 
 */
package renmopr.tourguide.util;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.kit.JsonKit;

/**
 * @author opunc
 *
 */
public class ExceptionInterceptor implements Interceptor {
	
	private static final Logger logger = LoggerFactory.getLogger(ExceptionInterceptor.class);

	@Override
	public void intercept(Invocation inv) {
		try {
			inv.invoke();
		} catch (Exception e) {
			logger.error("", e);
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("code", -1);
			map.put("message", "ERROR");
			inv.getController().renderJson(JsonKit.toJson(map));
			return ;
		}
	}
}
